<?php
/**
 * Created by PhpStorm.
 * User: chenyu
 * Date: 2017-09-11
 * Time: 15:30
 */

/**
 * @param $className
 * @return bool|mixed|null
 */


function __autoload($className)
{
    if(empty($className))
    {
        return false;
    }
    static  $cache = array();
    defined('DS') or define('DS',DIRECTORY_SEPARATOR);
    $basepath  = dirname(dirname(dirname(dirname(__DIR__))));
    $namespace = 'EpgApp';
    $pattern   = "/^(\\\.$namespace|$namespace)\\\.+/";
    $ext       = '.php';
    if(!empty($cache) && isset($cache[$className]))
    {
        return ;
    }
    if(preg_match($pattern,$className))
    {
        $file = str_replace('\\',DS,$className);
        if( DS === $file[0])
        {
            $file[0] = '';
        }
        $file = str_replace('EpgApp',$basepath,$file).$ext;
        if(file_exists($file))
        {
            $cache[$className] = $file;
            include($file);
        }
    }
    return  null;
}

return spl_autoload_register('__autoload');